import 'package:flutter/material.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';
import 'package:flutter/cupertino.dart';

class MessageSettingPage extends StatefulWidget {
  @override
  _MessageSettingPageState createState() => _MessageSettingPageState();
}

class _MessageSettingPageState extends State<MessageSettingPage> {
  bool _newMessageIsOn = true;
  bool _voiceIsOn = false;
  bool _shockIsOn = false;
  bool _newCustomIsOn = false;
  bool _longTimeIsOn = false;
  bool _followIsOn = false;
  bool _oldManIsOn = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('消息设置'),
        elevation: 0.5,
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            _itemCell('新消息通知', _newMessageIsOn, (value){setState(() {
              _newMessageIsOn = value;
            });}),
            Container(height: 10,color: Colours.bg_gray,),
            Padding(
              padding: EdgeInsets.all(15),
              child: Text('基础设置',style: TextStyles.textBoldDark18,),
            ),
            Container(height: 1,color: Colours.bg_gray,),
            _itemCell('声音', _voiceIsOn, (value){setState(() {
              _voiceIsOn = value;
            });}),
            Container(height: 1,color: Colours.bg_gray,),
            _itemCell('震动', _shockIsOn, (value){setState(() {
              _shockIsOn = value;
            });}),
            Container(height: 10,color: Colours.bg_gray,),
            Padding(
              padding: EdgeInsets.all(15),
              child: Text('分类设置',style: TextStyles.textBoldDark18,),
            ),
            Container(height: 1,color: Colours.bg_gray,),
            _itemCell('新客户通知', _newCustomIsOn, (value){setState(() {
              _newCustomIsOn = value;
            });}),
            Container(height: 1,color: Colours.bg_gray,),
            _itemCell('客户超时预警', _longTimeIsOn, (value){setState(() {
              _longTimeIsOn = value;
            });}),
            Container(height: 1,color: Colours.bg_gray,),
            _itemCell('跟进预警', _followIsOn, (value){setState(() {
              _followIsOn = value;
            });}),
            Container(height: 1,color: Colours.bg_gray,),
            _itemCell('长者生日提醒', _oldManIsOn, (value){setState(() {
              _oldManIsOn = value;
            });}),
            Container(height: 10,color: Colours.bg_gray,),
          ],
        ),
      ),
    );
  }

  Widget _itemCell(String title, bool isOn, Function(bool) onChange) {
    return Container(
      padding: EdgeInsets.fromLTRB(15, 5, 15, 5),
      width: double.infinity,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(
            title,
            style: TextStyles.textDark16,
          ),
          CupertinoSwitch(
            value: isOn,
            onChanged: onChange,
            activeColor: Colours.app_main,
          )
        ],
      ),
    );
  }
}
